package com.gkj.blog.business.enums;

public enum ArticleStatusEnum {
    UNPUBLISHED(0, "草稿"),
    PUBLISHED(1, "发布"),
    RECYCLE_ALL(2,"回收站"),
    RECYCLE_0(3,"草稿回收站"),
    RECYCLE_1(4,"发布回收站");
    private int code;
    private String desc;

    ArticleStatusEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static ArticleStatusEnum getRecover(ArticleStatusEnum status){
            if (3 == status.getCode()||status.getCode()==4) {
                return get(status.getCode()-3);
            }else {
                return get(0);
            }
    }
    public static ArticleStatusEnum getRecover(Integer status){
        if (3 == status||status==4) {
            return get(status-3);
        }else {
            return get(0);
        }
    }
    public static ArticleStatusEnum getRecycle(Integer status){
        if (1 == status||status==0) {
            return get(status+3);
        }else {
            return get(3);
        }
    }
    public static ArticleStatusEnum get(Integer code) {
        if (code == null) {
            return UNPUBLISHED;
        }
        ArticleStatusEnum[] statusEnums = ArticleStatusEnum.values();
        for (ArticleStatusEnum statusEnum : statusEnums) {
            if (statusEnum.getCode() == code) {
                return statusEnum;
            }
        }
        return UNPUBLISHED;
    }

    public int getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }
}
